using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameForKids
{
    class Couple
    {
        public string ImgLink;
        public string SoundLink;
        public Vector2 Position;
        public bool IsShow = true;
        public bool IsWaitToCheck = false;
        public bool OnRunTime = false;
        public int Height;
        public int Width;
        public float TimeForPlay;
        public bool OnClick = false;
        public float TimeForReclick;

        public bool OnPlay = false;
        public float TimeForReplay;

        public Couple(string imgLink, string soundLink, Vector2 position)
        {
            TimeForPlay = 2.0f;
            TimeForReclick = 1.0f;
            TimeForReplay = 1.0f;

            ImgLink = imgLink;
            SoundLink = soundLink;
            Position = position;
            IsShow = true;
            Height = Suport.GetTexture(ImgLink).Height;
            Width = Suport.GetTexture(ImgLink).Width;
        }

        public void Update(GameTime gametime)
        {
            if (OnRunTime == true)
            {
                TimeForPlay -= gametime.ElapsedGameTime.Milliseconds / 1000.0f;
            }

            if (OnClick == true)
            {
                TimeForReclick -= gametime.ElapsedGameTime.Milliseconds / 1000.0f;
            }

            if (TimeForReclick < 0.0f)
            {
                OnClick = false;
                TimeForReclick = 1.0f;
            }

            if (OnPlay == true)
            {
                TimeForReplay -= gametime.ElapsedGameTime.Milliseconds / 1000.0f;
            }

            if (TimeForReplay < 0.0f)
            {
                OnPlay = false;
                TimeForReplay = 1.0f;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            if (IsShow == true)
            {
                spriteBatch.Draw(Suport.GetTexture(ImgLink), new Vector2(Position.X - Width/2, Position.Y - Height/2), Color.White);
            }
        }

        public bool CheckTouch(TouchLocation touch)
        {
            Rectangle rec = new Rectangle((int)Position.X - Width/2, (int)Position.Y - Height/2, Width, Height);
            if (rec.Contains(new Point((int)touch.Position.X, (int)touch.Position.Y)) == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
